package com.hotelmanage.hm.serviceImpl;

import com.hotelmanage.hm.mapper.ServiceMapper;
import com.hotelmanage.hm.po.ServicePO;
import com.hotelmanage.hm.po.ServicePOExample;
import com.hotelmanage.hm.service.ServiceService;
import com.hotelmanage.hm.vo.ServiceVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ServiceServiceImpl implements ServiceService {

    @Resource
    private ServiceMapper serviceMapper;
    @Override
    public List<ServicePO> getByHotelId(int hotelid) {
        return serviceMapper.getByHotelId(hotelid);
    }

    @Override
    public List<ServicePO> getAll() {
        return serviceMapper.selectByExample(new ServicePOExample());
    }

    @Override
    public int newService(ServiceVO serviceVO) {
        ServicePO servicePO = new ServicePO();
        servicePO.setHotelid(serviceVO.getHotelid());
        servicePO.setName(serviceVO.getName());
        servicePO.setInstruction(serviceVO.getInstruction());
        return serviceMapper.insert(servicePO);
    }

    @Override
    public int editService(ServiceVO serviceVO) {
        ServicePO servicePO = new ServicePO();
        BeanUtils.copyProperties(serviceVO,servicePO);
        return serviceMapper.updateByPrimaryKeySelective(servicePO);


    }

    @Override
    public ServicePO get(int id) {

        ServicePOExample servicePOExample = new ServicePOExample();
        servicePOExample.or().andIdEqualTo(id);
        return serviceMapper.selectByPrimaryKey(id);
    }
}
